import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class SessionSettings extends JDialog {

	private final JPanel contentPanel = new JPanel();
    private Session session;
	/**
	 * Create the dialog.
	 */
	public SessionSettings(Session s) {
		setResizable(false);
		setBounds(100, 100, 323, 183);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		session = s;
		
		JLabel label = new JLabel("Session Name:");
		label.setBounds(10, 11, 238, 20);
		contentPanel.add(label);
		
		final JTextPane textPane = new JTextPane();
		textPane.setBounds(103, 11, 191, 20);
		contentPanel.add(textPane);
		
		JLabel lblSessionType = new JLabel("Session Type:");
		lblSessionType.setBounds(10, 45, 225, 20);
		contentPanel.add(lblSessionType);
		
		String[] comboBoxItems = {"Identity Matching", "Arbitrary Matching", "Symmetry", "Transitivity"};
		final JComboBox comboBox = new JComboBox(comboBoxItems);
		comboBox.setBounds(103, 45, 191, 20);
		contentPanel.add(comboBox);
		
		final JCheckBox chckbxShowProgressBar = new JCheckBox("Show Progress Bar");
		chckbxShowProgressBar.setBounds(10, 82, 151, 23);
		contentPanel.add(chckbxShowProgressBar);
		
		final JCheckBox chckbxRewardTokens = new JCheckBox("Reward Tokens");
		chckbxRewardTokens.setBounds(163, 82, 145, 23);
		contentPanel.add(chckbxRewardTokens);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						if (!textPane.getText().equals("")){
						   session.setName(textPane.getText());
						   session.setSessionType((String)comboBox.getSelectedItem());
						   session.setProgressBar(chckbxShowProgressBar.isSelected());
						   session.setbisRewardedPhase(chckbxRewardTokens.isSelected());
						   dispose();
						} else {
							JOptionPane.showMessageDialog(SessionSettings.this, "No session name has been entered. Please enter session name.", "Session Name Not Entered", JOptionPane.INFORMATION_MESSAGE);
						}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		
		textPane.setText(session.getName());
		comboBox.setSelectedItem(session.getSessionType());
		chckbxShowProgressBar.setSelected(session.getProgressBar());
		chckbxRewardTokens.setSelected(session.isRewardedPhase());
		
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setVisible(true);
	}
}
